package com.aliothservice.catfish.product.data;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.data.annotation.Id;

public class WarehouseService {
	
	public Map<String, Object> mapForSearchResult() {
		Map<String, Object> map = new HashMap<String, Object>();
		
		map.put("id", this.getId());
		map.put("keySpec", this.getKeySpec());
		map.put("temperatureSpec", this.getTemperatureSpec());
		map.put("name", this.getName());
		map.put("province", this.getProvince());
		map.put("city", this.getCity());
		map.put("district", this.getDistrict());
		map.put("address", this.getAddress());
		map.put("stock", this.getStock());
		map.put("price", this.getPrice());
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		map.put("startDate", formatter.format(this.getStartDate()));
		map.put("untilDate", formatter.format(this.getUntilDate()));
		map.put("stockTotal", this.getStockTotal());
		map.put("warehousePhotoId", this.getWarehousePhotoId());
		if (null != this.getIndividual()) {
			map.put("individual", this.getIndividual());
		}
		if (null != this.getEnterprise()) {
			map.put("enterprise", this.getEnterprise());
		}
		map.put("userHash", this.getUserHash());
		map.put("manInChargeName", this.getManInChargeName());
		if (this.getManInChargePhoneNumber().length() != 11) {
			map.put("manInChargePhoneNumber", this.getManInChargePhoneNumber());
		} else {
			String maskedPhoneNumber = String.format("%s*****%s", this.getManInChargePhoneNumber().substring(0, 2), this.getManInChargePhoneNumber().substring(7, 10));
			map.put("manInChargePhoneNumber", maskedPhoneNumber);
		}
		if (null != this.getDeviceSN()) {
			map.put("deviceSN", this.getDeviceSN());
		}
		
		return map;
	}
	
	public Map<String, Object> toMap() {
		Map<String, Object> map = new HashMap<String, Object>();

		map.put("id", this.getId());
		map.put("keySpec", this.getKeySpec());
		map.put("temperatureSpec", this.getTemperatureSpec());
		map.put("name", this.getName());
		map.put("province", this.getProvince());
		map.put("city", this.getCity());
		map.put("district", this.getDistrict());
		map.put("address", this.getAddress());
		map.put("stock", this.getStock());
		map.put("price", this.getPrice());
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		map.put("startDate", formatter.format(this.getStartDate()));
		map.put("untilDate", formatter.format(this.getUntilDate()));
		map.put("stockTotal", this.getStockTotal());
		map.put("warehousePhotoId", this.getWarehousePhotoId());
		if (null != this.getIndividual()) {
			map.put("individual", this.getIndividual());
		}
		if (null != this.getEnterprise()) {
			map.put("enterprise", this.getEnterprise());
		}
		map.put("userHash", this.getUserHash());
		if (null != this.getDeviceSN()) {
			map.put("deviceSN", this.getDeviceSN());
		}
		
		return map;
	}
	
	@Id
	private String id;
	
	// who owns this service
	private String userId;
	private String userHash;
	
	private String keySpec;
	private String temperatureSpec;
	
	private String name;
	private String province;
	private String city;
	private String district;
	private String address;
	
	private Integer stock;
	private Integer stockTotal;
	private Float price;
	
	private Date startDate;
	private Date untilDate;
	
	private String warehousePhotoId;
	
	private String individual;
	private String enterprise;
	
	private String manInChargeName;
	private String manInChargePhoneNumber;
	
	private String deviceSN;
	
	private LocalDateTime creationDate;

	public String getTemperatureSpec() {
		return temperatureSpec;
	}

	public void setTemperatureSpec(String temperatureSpec) {
		this.temperatureSpec = temperatureSpec;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getProvince() {
		return province;
	}

	public void setProvince(String province) {
		this.province = province;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getDistrict() {
		return district;
	}

	public void setDistrict(String district) {
		this.district = district;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getKeySpec() {
		return keySpec;
	}

	public void setKeySpec(String keySpec) {
		this.keySpec = keySpec;
	}

	public Integer getStock() {
		return stock;
	}

	public void setStock(Integer stock) {
		this.stock = stock;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getUntilDate() {
		return untilDate;
	}

	public void setUntilDate(Date untilDate) {
		this.untilDate = untilDate;
	}

	public Float getPrice() {
		return price;
	}

	public void setPrice(Float price) {
		this.price = price;
	}

	public Integer getStockTotal() {
		return stockTotal;
	}

	public void setStockTotal(Integer stockTotal) {
		this.stockTotal = stockTotal;
	}

	public String getWarehousePhotoId() {
		return warehousePhotoId;
	}

	public void setWarehousePhotoId(String warehousePhotoId) {
		this.warehousePhotoId = warehousePhotoId;
	}

	public String getIndividual() {
		return individual;
	}

	public void setIndividual(String individual) {
		this.individual = individual;
	}

	public String getEnterprise() {
		return enterprise;
	}

	public void setEnterprise(String enterprise) {
		this.enterprise = enterprise;
	}

	public String getUserHash() {
		return userHash;
	}

	public void setUserHash(String userHash) {
		this.userHash = userHash;
	}

	public String getManInChargeName() {
		return manInChargeName;
	}

	public void setManInChargeName(String manInChargeName) {
		this.manInChargeName = manInChargeName;
	}

	public String getManInChargePhoneNumber() {
		return manInChargePhoneNumber;
	}

	public void setManInChargePhoneNumber(String manInChargePhoneNumber) {
		this.manInChargePhoneNumber = manInChargePhoneNumber;
	}

	public String getDeviceSN() {
		return deviceSN;
	}

	public void setDeviceSN(String deviceSN) {
		this.deviceSN = deviceSN;
	}

	public LocalDateTime getCreationDate() {
		return creationDate;
	}

	public void setCreationDate(LocalDateTime creationDate) {
		this.creationDate = creationDate;
	}

}
